/*
 * !Drowning
 * May 29, 2011
 * TCSS 360
 * Schedule Project
 */
import java.util.ArrayList;
import java.util.List;


/**
 * User object that holds a username and preferences.
 * 
 * @author Jay Fernandez
 * @author Efim Todorasco edited on May 31
 * @version May 31, 2011
 */
public class User {
	
	/**
	 * The username of the user.
	 */
	private String my_username;
	
	/**
	 * List of preferred courses.
	 */
	private List<preference> my_preferences;
	
	/**
	 * Constructor that initializes with a given username.
	 * 
	 * @param the_username The username of the user.
	 */
	public User(String the_username) {
		
		setUsername(the_username);
		my_preferences = new ArrayList<preference>();
	}
	
	/**
	 * Adds a given preference to the user.
	 * 
	 * @param the_preference The preference to be added.
	 */
	public void addPreference(preference the_preference) {
		my_preferences.add(the_preference);
	}
	
	/**
	 * Removes the latest preference.
	 */
	public void removeLastPreference() {
		my_preferences.remove(my_preferences.size() - 1);
	}
	
	/**
	 * Sets the username of the user.
	 * 
	 * @param the_username The username to set.
	 */
	public void setUsername(String the_username) {
		my_username = the_username;
	}

	/**
	 * @return the username.
	 */
	public String getUsername() {
		return my_username;
	}

	/**
	 * @return the list of preferences.
	 */
	public List<preference> getPreferences() {
		return my_preferences;
	}
	
	/**
	 * Sets the preferences from a given list of preferences.
	 * 
	 * @param the_preferences The list of preferences.
	 */
	public void setPreferences(List<preference> the_preferences) {
		my_preferences.clear();
		for (int i = 0; i < my_preferences.size(); i++) {
			my_preferences.add(my_preferences.get(i));
		}
	}
	public String toString() {
		String result;
		result = "User name: " + getUsername();
		result = result + "\n" + getPreferences();
		return result;
	}
}
